package com.hx.er.action.manager.rest;

import org.springframework.beans.factory.annotation.Autowired;

import com.hx.er.action.base.ErManagerAction;
import com.hx.er.bean.base.AnnouncementBean;
import com.hx.er.bean.base.RestraurantBean;
import com.hx.er.common.system.ErLanguages;
import com.hx.er.service.manager.IManagerRestService;

public class ManagerAnnEditAction extends ErManagerAction {
	// 序列化ID
	private static final long serialVersionUID = -8109125736638585366L;

	// 多语言标签名
	private String labelLang1;
	private String labelLang2;
	private String labelLang3;
	private String labelLang4;
	private String labelLang5;

	// 餐厅bean
	private RestraurantBean restBean;

	// 公告bean
	private AnnouncementBean annBean;

	@Autowired
	private IManagerRestService managerRestService;

	public String init() {
		this.initPage();
		return SUCCESS;
	}

	public String save() {
		this.annBean.setCreateUserId(super.userInfoLogin.getUserId());
		this.annBean.setUpdateUserId(super.userInfoLogin.getUserId());
		this.annBean.setRestId(super.restId);
		
		int count = this.managerRestService.updateAnn(this.annBean);
		if (count == 0) {
			this.initPage();
			this.addActionError(EDIT_FAILURE_MSG);
			return INPUT;
		}

		this.addActionMessage(EDIT_SUCCESS_MSG);
		return SUCCESS;
	}

	private void initPage() {
		// 检索餐厅
		this.restBean = this.managerRestService.getRestById(super.restId);

		// 检索公告
		AnnouncementBean annBean = new AnnouncementBean();
		annBean.setRestId(super.restId);
		this.annBean = this.managerRestService.getAnnAlive(annBean);

		// 语言
		if (this.restBean.getLangId1() != 0) {
			this.labelLang1 = ErLanguages.getLocale(this.restBean.getLangId1()).getLanguage().toUpperCase();
		}
		if (this.restBean.getLangId2() != 0) {
			this.labelLang2 = ErLanguages.getLocale(this.restBean.getLangId2()).getLanguage().toUpperCase();
		}
		if (this.restBean.getLangId3() != 0) {
			this.labelLang3 = ErLanguages.getLocale(this.restBean.getLangId3()).getLanguage().toUpperCase();
		}
		if (this.restBean.getLangId4() != 0) {
			this.labelLang4 = ErLanguages.getLocale(this.restBean.getLangId4()).getLanguage().toUpperCase();
		}
		if (this.restBean.getLangId5() != 0) {
			this.labelLang5 = ErLanguages.getLocale(this.restBean.getLangId5()).getLanguage().toUpperCase();
		}
	}

	public RestraurantBean getRestBean() {
		return restBean;
	}

	public void setRestBean(RestraurantBean restBean) {
		this.restBean = restBean;
	}

	public AnnouncementBean getAnnBean() {
		return annBean;
	}

	public void setAnnBean(AnnouncementBean annBean) {
		this.annBean = annBean;
	}

	public String getLabelLang1() {
		return labelLang1;
	}

	public String getLabelLang2() {
		return labelLang2;
	}

	public String getLabelLang3() {
		return labelLang3;
	}

	public String getLabelLang4() {
		return labelLang4;
	}

	public String getLabelLang5() {
		return labelLang5;
	}

}
